package com.itheima.controller;

import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/clazzs")
@Slf4j
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    /**
     * 分页查询
     * @param clazzQueryParam 查询参数
     * @return
     * @RequestParam 注解：将请求参数与方法参数进行绑定 同时可以设置默认值
     */
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {
        log.info("分页查询，参数：{}",clazzQueryParam);
        if (clazzQueryParam.getPageSize()<=0){
            clazzQueryParam.setPageSize(10);
        }
        //1.调用业务逻辑层查询分页数据
        PageResult pageResult = clazzService.page(clazzQueryParam);
        //2.返回结果
        return Result.success(pageResult);
    }
}
